var setting = {
    check: {
        enable: true,
        //chkStyle: "checkbox",
        //chkboxType: {"Y":"", "N":""}
        chkStyle: "radio",
        radioType: "all"
    },
    view: {
        dblClickExpand: false
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onClick: onClick,
        onCheck: onCheck
    }
};

function onClick(e, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj(treeId);
    zTree.checkNode(treeNode, !treeNode.checked, null, true);
    hideMenu();
    return false;
}

function onCheck(e, treeId, treeNode) {
    var nodeId = $("#"+treeId).parent("div").prev().prev().attr("id");
    var entityId = $("#"+treeId).parent("div").prev().attr("entityId");
    var zTree = $.fn.zTree.getZTreeObj(treeId),nodes = zTree.getCheckedNodes(true),id = "",name = "";
    for (var i = 0; i < nodes.length; i++) {
        id += nodes[i].id + ",";
        name += nodes[i].name + ",";
    }
    if (name.length > 0 ){
        id = id.substring(0, id.length-1);
        name = name.substring(0, name.length-1);
    }
    $("#"+nodeId).val(id);
    $("#"+nodeId+"_osv").val(name);
}

/**
 * 所属部门点击事件
 * @param node
 */
function deptQuoteClick(node) {
    var cityOffset = $(node).offset();
    $(".menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + $(node).outerHeight() + "px"}).slideDown("fast");
    $("body").bind("mousedown", onBodyDown);
}

function hideMenu() {
    $(".menuContent").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);
}

function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents(".menuContent").length>0)) {
        hideMenu();
    }
}
